import { defineStore } from 'pinia'
import { getDetailInfo } from '@/services/modules/detail'

const useDetailStore = defineStore('detail', {
  state: () => ({
    detailInfo: [],
  }),
  getters: {
    // 轮播图信息
    getHousePicture() {
      return this.detailInfo?.mainPart?.topModule?.housePicture
    },
    //房屋设施信息
    getHouseFacility() {
      return this.detailInfo?.mainPart?.dynamicModule?.facilityModule?.houseFacility
    },
    // 房东介绍信息
    getLandlordModule() {
      return this.detailInfo?.mainPart?.dynamicModule?.landlordModule
    },
    // 热门评论信息
    getComment() {
      return this.detailInfo?.mainPart?.dynamicModule?.commentModule
    },
    // 预定须知信息
    getNotice() {
      return this.detailInfo?.mainPart?.dynamicModule?.rulesModule?.orderRules
    },
    // 价格说明
    getiIntro() {
      return this.detailInfo?.mainPart?.introductionModule
    },
    // 经纬度坐标信息
    getMap() {
      return this.detailInfo?.mainPart?.dynamicModule?.positionModule
    },
    // 房价信息
    getPrice() {
      return this.detailInfo?.pricePart?.priceModule
    },
  },
  actions: {
    async getDetailInfoAction(houseId) {
      const res = await getDetailInfo(houseId)
      this.detailInfo = res.data
    },
  },
})

export default useDetailStore
